package com.gxa.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gxa.common.R;
import com.gxa.entity.DistrictSysInfoStatistics;
import com.gxa.mapper.InfoRegStatisticsMapper;
import com.gxa.service.InfoRegStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class InfoRegStatisticsServiceImpl implements InfoRegStatisticsService {

    @Autowired
    private InfoRegStatisticsMapper infoRegStatisticsMapper;


    /**
     * 分页查询信息登记表
     * @param currentPage
     * @return
     */
    @Override
    public R findinfostatistics(Integer currentPage) {

        R r = new R();
        Date currentDate = new Date();

        DistrictSysInfoStatistics todayInfo = new DistrictSysInfoStatistics();
        int todyPatient = infoRegStatisticsMapper.findTodyPatient(currentDate);
        int todyContact = infoRegStatisticsMapper.findTodyContact(currentDate);
        int todaySecondary = infoRegStatisticsMapper.findTodaySecondary(currentDate);
        int todayCommon = infoRegStatisticsMapper.findTodayCommon(currentDate);

        todayInfo.setDate(currentDate);
        todayInfo.setConfirmedNum(todyPatient);
        todayInfo.setContactNum(todyContact);
        todayInfo.setSecondaryNum(todaySecondary);
        todayInfo.setCommonNum(todayCommon);

        int row = infoRegStatisticsMapper.addTodayInfo(todayInfo);

        if (row > 0){
            Page page = PageHelper.startPage(currentPage,10);

            List<DistrictSysInfoStatistics> districtSysInfoStatisticsList = infoRegStatisticsMapper.findInfoList();

            int total =  (int)page.getTotal();

            Map map =new HashMap();

            map.put("total",total);
            map.put("districtSysInfoStatisticsList",districtSysInfoStatisticsList);
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(map);

        }else {
            r.setCode(400);
            r.setMsg("查询失败");
        }

        return r;
    }

    /**
     * 根据日期查询信息登记统计表
     * @param currentPage
     * @param currentDate
     * @return
     */
    @Override
    public R findinfostatisticsbydate(Integer currentPage, Date currentDate) {

        R r = new R();

        Page page = PageHelper.startPage(currentPage,10);

        List<DistrictSysInfoStatistics> districtSysInfoStatisticsList = infoRegStatisticsMapper.findInfoListByDate(currentDate);

        int total =  (int)page.getTotal();

        Map map =new HashMap();

        map.put("total",total);
        map.put("districtSysInfoStatisticsList",districtSysInfoStatisticsList);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(map);

        return r;
    }
}
